﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;
using BLToolkit.Data;
using BLToolkit.Data.Linq;

namespace DAL
{
    public class BanRepository:IBanRepository
    {
        private readonly DbManager db = new DbManager("QuanLyBilliards");
        public Ban GetByTenBan(string tenBan)
        {
            return db.GetTable<Ban>().SingleOrDefault(x => x.TenBan==tenBan);
        }


        public IQueryable<Ban> GetAll()
        {
            return db.GetTable<Ban>();
        }
        public IQueryable<Ban> GetAllCafe()
        {
            return db.GetTable<Ban>().Where(bt => bt.Cafe == true);
        }

        public IQueryable<Ban> GettAllBillards()
        {
            return db.GetTable<Ban>().Where(bt => bt.Cafe == false);
        }
        public IQueryable<Ban> GetAllTheoLoai(bool a)
        {
            return db.GetTable<Ban>().Where(aa => aa.Cafe == a);
        }
        //public IQueryable<Ban> GetAllTheoLoaiVaTrangThai(bool a,bool b)
        //{
        //    return db.GetTable<Ban>().Where(asa => asa.LoaiBan == a && asa.TrangThai == b);
        //}

        //thuy
        public bool AddNew(Ban ban)
        {
            return db.Insert(ban) > 0;
        }

        public bool Update(Ban ban)
        {
            return db.Update(ban) > 0;
        }

        public bool Delete(Ban ban)
        {
            return db.Delete(ban) > 0;
        }
        public IQueryable<Ban> TimbanTheoTT(bool tt)
        {
            return db.GetTable<Ban>().Where(bt => bt.TrangThai == tt );
        }

        public IQueryable<Ban> DSBanTheoTen(string ten)
        {
            return db.GetTable<Ban>().Where(bt => bt.TenBan == ten);
        }

        /// <summary>
        /// //////////////
        /// </summary>
        /// <param name="ban"></param>
        void IBanRepository.AddNew(Ban ban)
        {
            throw new NotImplementedException();
        }

        void IBanRepository.Delete(Ban ban)
        {
            throw new NotImplementedException();
        }
    }
}
